﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Meeting.DBUtility;
using Newtonsoft.Json;

namespace Meeting.BLL
{
    public  class Summary
    {
        public string errorString = "";

        //获取会议纪要
        public string GetAllSummary(int pageIndex, int pageSize, string filter)
        {
            try
            {
                int nAllRecord = 0, nAllPages = 0;
                DataTable dt = DbHelperSQL.GetPage("  Id  ", " Id,MeetingId,(Select Name From Meeting Where MeetingId=MeetingSummary.MeetingId) As MeetingName, Sort,Path,Name,Format,UploadDate,ImageCount,Comment,IsActive,EmployeeId,EmployeeName,EmployeeTitle,RoleId,IsSubmit, Agent,ExtNumber ", " MeetingSummary ", filter, " UploadDate Desc ",
                                pageIndex, pageSize, out nAllRecord, out nAllPages);
                if (dt == null) return "";
                Model.JsonGrid jr = new Model.JsonGrid();
                jr.total = nAllRecord;
                jr.rows = dt;

                Newtonsoft.Json.Converters.IsoDateTimeConverter timeConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter();
                timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm";

                return JsonConvert.SerializeObject(jr, timeConverter);
            }
            catch (Exception ex)
            {
                errorString = ex.Message;
                return "";
            }
        }

        //删除纪要
        public bool DeleteTopic(string Id)
        {
            string sql = "Delete From MeetingSummary Where Id = '" + Id + "'  ";
            
            try
            {
                int i = DbHelperSQL.ExecuteSql(sql);
                if (i > 0) return true;
                errorString = "没有找到数据";
                return false;
            }
            catch (Exception ex)
            {
                errorString = ex.Message;
                return false;
            }
        }

    }
}
